#!/bin/bash
HOSTNAME="127.0.0.1"
PORT=3306
MYSQL_USER=yapai
MYSQL_PASSWORD=ypkj@1234
MYSQL_ROOT_PASSWORD=APkj@1234
force=""
currentHome=$(cd "$(dirname "$0")";pwd)
YAPAI_HOME=$(dirname "$currentHome")
HASH=`curl http://localhost:8700/sld/random/getReadomMd5 | sed -ne 's/{"//p' |sed -ne's/"}//p'| awk -F "[ \" ]+" '{print $NF}'`
echo "获取的服务授权密钥:"${HASH}
# openssl md5
SHOWPASS="123456"
# PASS=`printf  ${SHOWPASS} | openssl md5 | awk '{print $NF}'`
PASS=`mysql -hlocalhost -uyapai -p${MYSQL_PASSWORD} -e "use shuiliandong; select * from t_sys_user where user_name='ypkj'\G" 2>&1 | sed -n '2,$p' | grep -E 'password' | awk -F ':' '{print $2}'`
LP=`printf  ${PASS}${HASH}|openssl md5 | awk '{print $NF}'`
TOKENMSG=`curl -X POST "http://localhost:8700/sld/oauth/token?username=ypkj&password=${LP}&grant_type=password&client_id=Auth&client_secret=user123"`
TOKEN=`echo ${TOKENMSG} | grep -oE 'access_token":"[0-9a-zA-Z_.\-]+' | awk -F "[:\"]+" '{print $2}'`
#TOKEN=`echo ${TOKENMSG} | grep -E 'access_token":"[0-9a-zA-Z]+'`
LAST_TOKEN="Bearer "${TOKEN}

curl -si -H 'Authorization:'"${LAST_TOKEN}"'' 'http://'"${HOSTNAME}"':8700/sld/dept/treeselect?reOrder=1'
curl -si -H 'Authorization:'"${LAST_TOKEN}"'' 'http://'"${HOSTNAME}"':8700/nanshan/location/tree?reOrder=1'
curl -si -H 'Authorization:'"${LAST_TOKEN}"'' 'http://'"${HOSTNAME}"':8700/nanshan/assetstype/tree?reOrder=1'
